package com.cc.demo2;

import org.apache.http.HttpHost;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;

import java.io.IOException;

//查询索引中的所有数据
public class DeleteClient1 {
    public static  void main(String[] args) throws IOException {
        //创建java和es的链接
        HttpHost httpHost = new HttpHost("127.0.0.1", 9200, "http");
        RestClientBuilder builder = RestClient.builder(httpHost);
        RestHighLevelClient client = new RestHighLevelClient(builder);
        System.out.println(client.indices());

        //删除文档  delete /good/_doc/1
        DeleteRequest deleteRequest = new DeleteRequest().index("good").id("1");
        //发送删除请求
        DeleteResponse response = client.delete(deleteRequest, RequestOptions.DEFAULT);
        System.out.println("删除文档结果：" + response.toString());


        //关闭连接
        client.close();
    }
}
